package org.bozo.im.service.core.authenticator;

import org.bozo.im.R;
import org.bozo.im.activity.Constants;

import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.accounts.NetworkErrorException;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

public class EmptyAuthenticator extends AbstractAccountAuthenticator {

	public static String EMPTY_ACCOUNT = "empty-account";
	
	private Context mContext;

	public EmptyAuthenticator(Context pContext) {
		super(pContext);
		mContext = pContext;
	}

	@Override
	public Bundle addAccount(AccountAuthenticatorResponse pResponse, String pAccountType, String pAuthTokenType, String[] pRequiredFeatures, Bundle pOptions) throws NetworkErrorException {

		Bundle lRes = new Bundle();
		// ---------------------------------------------------------------------------------------
		Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.service.core.authenticator.EmptyAuthenticator.addAccount ---------- ");
		// ---------------------------------------------------------------------------------------
		try {
			String lName = mContext.getResources().getString(R.string.account_name);
			String lType = pAccountType;

			lRes.putString(AccountManager.KEY_ACCOUNT_TYPE, lType);
			lRes.putString(AccountManager.KEY_ACCOUNT_NAME, lName);

			Account lAccount = new Account(lName, lType);

			AccountManager.get(mContext).addAccountExplicitly(lAccount, null, null);

			lRes.putParcelable(EMPTY_ACCOUNT, lAccount);
			
		} catch (Exception e) {
			// ---------------------------------------------------------------------------------------
			Log.e(Constants.ACTIVITY_TAG, "org.bozo.im.service.core.authenticator.EmptyAuthenticator.addAccount ---------- Exception: ", e);
			// ---------------------------------------------------------------------------------------
		}
		return lRes;
	}

	@Override
	public Bundle confirmCredentials(AccountAuthenticatorResponse pResponse, Account pAccount, Bundle pOptions) throws NetworkErrorException {
		// TODO Auto-generated method stub
		// ---------------------------------------------------------------------------------------
		Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.service.core.authenticator.EmptyAuthenticator.confirmCredentials ---------- ");
		// ---------------------------------------------------------------------------------------
		return null;
	}

	@Override
	public Bundle editProperties(AccountAuthenticatorResponse pResponse, String pAccountType) {
		// TODO Auto-generated method stub
		// ---------------------------------------------------------------------------------------
		Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.service.core.authenticator.EmptyAuthenticator.getAuthToken ---------- ");
		// ---------------------------------------------------------------------------------------
		return null;
	}

	@Override
	public Bundle getAuthToken(AccountAuthenticatorResponse pResponse, Account pAccount, String pAuthTokenType, Bundle pOptions) throws NetworkErrorException {
		// TODO Auto-generated method stub
		// ---------------------------------------------------------------------------------------
		Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.service.core.authenticator.EmptyAuthenticator.getAuthToken ---------- ");
		// ---------------------------------------------------------------------------------------
		return null;
	}

	@Override
	public String getAuthTokenLabel(String pAuthTokenType) {
		// TODO Auto-generated method stub
		// ---------------------------------------------------------------------------------------
		Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.service.core.authenticator.EmptyAuthenticator.getAuthTokenLabel ---------- ");
		// ---------------------------------------------------------------------------------------
		return null;
	}

	@Override
	public Bundle hasFeatures(AccountAuthenticatorResponse pResponse, Account pAccount, String[] pFeatures) throws NetworkErrorException {
		// TODO Auto-generated method stub
		// ---------------------------------------------------------------------------------------
		Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.service.core.authenticator.EmptyAuthenticator.updateCredentials ---------- ");
		// ---------------------------------------------------------------------------------------
		return null;
	}

	@Override
	public Bundle updateCredentials(AccountAuthenticatorResponse pResponse, Account pAccount, String pAuthTokenType, Bundle pOptions) throws NetworkErrorException {
		// TODO Auto-generated method stub
		// ---------------------------------------------------------------------------------------
		Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.service.core.authenticator.EmptyAuthenticator.updateCredentials ---------- ");
		// ---------------------------------------------------------------------------------------
		return null;
	}

}
